package wechat.base.snd.domain

import java.io.File
import org.apache.log4j.Logger
import wechat.base.snd.QRCode
import wechat.base.snd.QRCodeManager
import wechat.base.snd.WCServiceApp
import wechat.base.snd.util.ExecGet

class SqrCode {
	static Logger logger = Logger::getLogger("SqrCode")
	
	def static File getSqrcodeFile(WCServiceApp app, String info){
//		new File(typeof(SqrCode).getClassLoader().getResource('sample.jpg').getFile())
		try{
			val qrcode = new QRCode(info);
			new QRCodeManager(app)=>[
				genPermTicket(qrcode)
				logger.info(qrcode.ticket)				
			]
			ExecGet::excuteGetImg("https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket="+qrcode.ticket, info+".jpg")
		}
		catch (Exception e){
			e.printStackTrace
			logger.error("Failed to get the sql file from weixin")
			null
		}
	}
}
